home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / server / startclients.c < prev    next >
C/C++ Source or Header  |  1994-11-29  |  2KB  |  109 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <dos/dostags.h>
  5.  
  6. #include "/include/server.h"
  7.  
  8. #include <clib/exec_protos.h>
  9. #include <clib/dos_protos.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. extern struct List ClientsList;
  14. extern UWORD TotalClients;
  15.  
  16. #define MAXCLIENTS 100
  17.  
  18. struct TagItem systags[4] = { SYS_Asynch, TRUE, SYS_Input, NULL, SYS_Output, NULL, TAG_END };
  19.  
  20.  
  21. BOOL StartClient( struct ClientNode *node )
  22. {
  23. BPTR lock, prev_lock, check_lock;
  24. char path[CLIENTNAME_MAXLENGTH], *filename, *pathname;
  25. BOOL success = FALSE;
  26. LONG dos_report;
  27.  
  28. strcpy( path, node->cn_ClientName );
  29. filename = FilePart( path );
  30. pathname = PathPart( path );
  31. if ( pathname != path )
  32.     *pathname = 0;
  33. if ( lock = Lock( path, ACCESS_READ ) )
  34.     {
  35.     prev_lock = CurrentDir( lock );
  36.  
  37.     if ( check_lock = Lock( filename, ACCESS_READ ) )
  38.         {
  39.         UnLock( check_lock );
  40.         dos_report =  SystemTagList( filename, systags );
  41.         if ( dos_report != -1 )
  42.             success = TRUE;
  43.         }
  44.     CurrentDir( prev_lock );
  45.     UnLock( lock );
  46.     }
  47. return success;
  48. }
  49.  
  50.  
  51. void AddClient( char *newname )
  52. {
  53. struct ClientNode *node;
  54.  
  55. if ( node = AllocVec( sizeof(struct ClientNode), MEMF_ANY | MEMF_CLEAR ) )
  56.     {
  57.     strcpy( node->cn_ClientName, newname );
  58.     node->cn_Node.ln_Name = FilePart( node->cn_ClientName );
  59.     AddTail( &ClientsList, node );
  60.     TotalClients++;
  61.     }
  62.  
  63. }
  64.  
  65.  
  66. void GetClientNames( char *listname )
  67. {
  68. BPTR handle;
  69. struct FileInfoBlock fib;
  70. register ULONG size;
  71. register char *ptr, *current;
  72. register char newclient[CLIENTNAME_MAXLENGTH];
  73. register UBYTE n;
  74.  
  75. if ( handle = Open( listname, MODE_OLDFILE ) )
  76.     {
  77.     if ( ExamineFH( handle, &fib ) )
  78.         {
  79.         size = fib.fib_Size;
  80.         if ( ptr = AllocVec( size, MEMF_ANY ) )
  81.             {
  82.             Read( handle, ptr, size );
  83.  
  84.             current = ptr;
  85.             while( current < ( ptr + size ) )
  86.                 {
  87.                 n = 0;
  88.                 while( *current != '\n' && current < ( ptr + size ) )
  89.                     newclient[n++] = *current++;
  90.                 newclient[n] = 0;
  91.                 current++;
  92.                 AddClient( newclient );
  93.                 }
  94.             FreeVec( ptr );
  95.             }
  96.         }
  97.     Close( handle );
  98.     }
  99. }
  100.  
  101.  
  102. void DropClientNames( void )
  103. {
  104. struct ClientNode *node;
  105.  
  106. while ( node = (struct ClientNode *)RemHead( &ClientsList ) )
  107.     FreeVec( node );
  108. }
  109.